#ifndef TCP_CLIENT_H
#define TCP_CLIENT_H

#include "protocol.h"

struct Client
{
    public:
        int fd;
        struct sockaddr_in addr;
        int port;
    
    public:
        Client(int _fd, struct sockaddr_in _addr)
        {
            fd = _fd;
            addr = _addr;
        }
        
        Client(int port = 8080) // 默认8080端口
        {
            fd = socket(AF_INET, SOCK_STREAM, 0);
            if(fd == -1)
            {
                cerr << "socket failed" << endl;
                return;
            }

            addr.sin_family = AF_INET; 
            addr.sin_addr.s_addr = inet_addr("127.0.0.1"); 
            addr.sin_port = htons(port); 
        }
        ~Client()
        {
            close(fd);
        }

        void start();
};

#endif